import 'package:base/main.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper_plus/flutter_swiper_plus.dart';
import 'package:module_home/pages/home/view_models/banner_vm.dart';

class HomeBannerWidget extends StatefulWidget {
  BannerVM vm;

  HomeBannerWidget({super.key, required this.vm});

  @override
  State<HomeBannerWidget> createState() => _HomeBannerWidgetState();
}

class _HomeBannerWidgetState extends State<HomeBannerWidget> {
  int _currentIndex = 0;

  final SwiperController _controller = SwiperController();

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Container(
          height: 88,
          margin: EdgeInsets.all(16),
          child: Obx(() => Swiper(
                controller: _controller,
                itemBuilder: (BuildContext context, int index) {
                  return Image.asset(
                    "assets/images/slices/${widget.vm.banners[index]}.png",
                    fit: BoxFit.fill,
                  );
                },
                onIndexChanged: (index) =>
                    setState(() => _currentIndex = index),
                itemCount: widget.vm.banners.length,
                autoplay: true,
                autoplayDelay: 3000,
                duration: 800,
                loop: true,
                scale: 0.9,
                viewportFraction: 1,
                curve: Curves.easeInOut,
                pagination: const SwiperPagination(
                  alignment: Alignment.bottomCenter,
                  margin: EdgeInsets.all(10.0),
                  builder: DotSwiperPaginationBuilder(
                    color: Colors.grey,
                    activeColor: Colors.blue,
                    size: 6.0,
                    activeSize: 8.0,
                  ),
                ),
              )),
        ),
      ],
    );
  }
}
